package com.sgy;

import com.sgy.entity.ClientFilterUrl;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author shenguangyang
 * @date 2022-08-14 8:38
 */
public class ClientFilterUrlMgt {
    private static final Map<String, ClientFilterUrl> clientFilterUrlMap = new ConcurrentHashMap<>();

    public static void add(ClientFilterUrl clientFilterUrl) {
        clientFilterUrlMap.put(clientFilterUrl.getUrl(), clientFilterUrl);
    }

    public static void remove(String url) {
        clientFilterUrlMap.remove(url);
    }

    public static ClientFilterUrl findByUrl(String url) {
        if (url == null || "".equals(url)) {
            return null;
        }
        for (Map.Entry<String, ClientFilterUrl> entry : clientFilterUrlMap.entrySet()) {
            if (url.contains(entry.getKey())) {
                return entry.getValue();
            }
        }
        return null;
    }
}
